package com.wzxy.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexUtils {

	public static final String numReg = "[^0-9]";
	public static final String dateReg = "[0-9]{4}[-][0-9]{1,2}[-][0-9]{1,2}[ ][0-9]{1,2}[:][0-9]{1,2}[:][0-9]{1,2}";
	
	/**
	 * 获取字符串中的数字
	 * @param s
	 * @return
	 */
	public static String getNum(String s){
		Pattern pattern = Pattern.compile(numReg);
		Matcher matcher = pattern.matcher(s);
		return matcher.replaceAll("").trim();		
	}
	
	/** 查看:10249   评论:101   来源:藤县警务在线   时间:2017-06-06 12:05:33 */
	public static String getFormatDate(String s){
		Pattern pattern = Pattern.compile(dateReg);
		Matcher matcher = pattern.matcher(s);
        String dateStr = null;  
        if(matcher.find()){  
          dateStr = matcher.group(0);  
        }
		return dateStr.toString();
	}
	
	public static void main(String[] args) {
		String s = "查看:10249   评论:101   来源:藤县警务在线   时间:2017-06-06 12:05:33";
		System.out.println(getFormatDate(s));
	}
	
}
